
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>信息终端导入</title>
		<%@ include file="/commons/css_js_head.jsp"%>

<script language="JavaScript">
		function closeWidows()
		{
			self.parent.tb_remove();
		}
		
		function upload() {
			var file_url = $("#fileUpload").val();
			if(end_with(file_url, "xls")) {
				$("#div_bar").css('display','block'); 
				$("#upload_submit").attr("disabled", true);
				$("#close_button").attr("disabled", true); 
				$("#upload_form").ajaxSubmit({
				async: false,
				type: "POST",
				dataType:"json",
				cache: false,
				success: function(date){
				    var results = date.result;
				    var s =results.split(":");
				    var result = s[0];
					if(result=="0")
					{
						alert("导入成功");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					else if(result=="1")
					{
						alert("导入失败,文件不能为空");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					else if(result=="2")
					{
						alert("上传Excel文件不能大于5000行");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					else if(result=="3")
					{
						alert("上传Excel文件只能为二列");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					else if(result=="4")
					{
					    
						alert("上传Excel文件中,"+s[1]+"不存在，请修改后得新导入！");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					else if(result=="5")
					{
						alert("上传Excel文件中,"+s[1]+"已存在，请修改后得新导入！");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					else{
					    alert("上传Excel文件出错");
						window.close();
						//parent.window.location.reload();
						parent.window.document.forms[0].submit();
					}
					
				}
			});
			}
			else
				alert("请选择以xls结尾的Excel文件");
		}
		
		function end_with(file_url, str){  
			if(str == null || str == "" || file_url.length == 0 || str.length > file_url.length)  
				return false;  
			if(file_url.substring(file_url.length-str.length)==str)  
				return true;  
			else  
				return false;  
				
			return true;  
		}
</script>
	</head>

	<body style="overflow-x: hidden">
		<div class="mTitle">
			<span class="hidsearch"></span>
			<b class="bbig">信息终端导入</b> 带
			<b class="fred"> * </b>号为必填项
		</div>

		
		
		<s:form id="upload_form" action="tsMachinesAction!importMachines" namespace="/base" method="POST" enctype="multipart/form-data" >
            <s:file id="fileUpload" name="fileUpload" label="上传的文件" size="45"/>
                               请选择后缀为.xls的Excel文件<br />
                               不大于5000行，2列，第1列为信息终端编号，第2列为终端类型。<br /><br />
                                模板下载 <a href="<%=request.getContextPath() %>/machines.xls" target="_blank">信息终端导入模板.xls</a>
            <br /> <br />                 
        </s:form>
        
        <!-- button -->
		  <div class="openBtn">
		  	<button class="btn" id="upload_submit" onclick="upload();" title="点击提交" style="width:80px;"><b>上传文件</b></button>
		  	&nbsp;&nbsp;&nbsp;&nbsp;
			<button class="btn" id="close_button" onclick="closeWidows();" title="关闭窗口" style="width:80px;"><b>关闭窗口</b></button>
			<div style="display: none" id="div_bar">正在上传，请稍候......</div>
		  </div>
		  <!-- end button -->

	</body>


</html>
